﻿/*
____
 L|ypps Web controls for ASP.NET

Copyright (c) 2009 Alessandro Zifiglio, http://www.Typps.com
EMail: alessandro@Typps.com

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
namespace Typps.Tests
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using Typps;

    [TestClass]
    public class UnitTestHtmlFormatter
    {
        #region Methods

        [TestMethod]
        public void ParseAndFormatButIgnoreCssStyleBlocks()
        {
            HtmlFormatter p = new HtmlFormatter(" ", true);
            string html = "<html>\r\n<head>\r\n<style type=\"text/css\">\r\n    ol.alpha li  { list-style: lower-alpha }\r\n    ul li        { list-style: disc }\r\n  </style>\r\n</head>\r\n  <body>\r\n    <ol class=\"alpha\">\r\n      <li>level 1\r\n      <ul>\r\n         <li>level 2</li>\r\n      </ul>\r\n    </li>\r\n    </ol>\r\n  </body>\r\n</html>";
            Assert.IsTrue(p.Parse(html.ToCharArray()).Equals("\n<html>\n <head>\n  <style type=\"text/css\">\r\n    ol.alpha li  { list-style: lower-alpha }\r\n    ul li        { list-style: disc }\r\n  </style>\n </head>  \n <body>    \n  <ol class=\"alpha\">      \n   <li>level 1      \n    <ul>         \n     <li>level 2\n     </li>      \n    </ul>    \n   </li>    \n  </ol>  \n </body>\n</html>", StringComparison.OrdinalIgnoreCase));
        }

        [TestMethod]
        public void ParseAndFormatButIgnoreScriptBlocksElements()
        {
            HtmlFormatter p = new HtmlFormatter(" ", true);
            string html = "<html>\r\n<head>\r\n<title>This is an HTML document</title>\r\n<script type=\"text/javascript\">\r\n    var a=\"abc\";\r\n    var b=\"def\";\r\n    var d=false;\r\n    var f=\"ho ho ho\";\r\n</script>\r\n</head>\r\n  <body>\r\n    <ol class=\"alpha\">\r\n      <li>level 1</li>\r\n      <ul>\r\n         <li>level 2</li>\r\n      </ul>\r\n    </ol>\r\n  </body>\r\n</html>";
            Assert.IsTrue(p.Parse(html.ToCharArray()).Equals("\n<html>\n <head>\n  <title>This is an HTML document\n  </title>\n </head>  \n <body>    \n  <ol class=\"alpha\">      \n   <li>level 1\n   </li>      \n   <ul>         \n    <li>level 2\n    </li>      \n   </ul>    \n  </ol>  \n <script type=\"text/javascript\">\r\n    var a=\"abc\";\r\n    var b=\"def\";\r\n    var d=false;\r\n    var f=\"ho ho ho\";\r\n </script>\n </body>\n</html>", StringComparison.OrdinalIgnoreCase));
        }

        [TestMethod]
        public void ParseAndFormatDeeplyNestedStructure()
        {
            HtmlFormatter p = new HtmlFormatter(" ", true);
            string html = "<a><b><c><d></d></c></b></a>";
            Assert.IsTrue(p.Parse(html.ToCharArray()).Equals("\n<a>\n <b>\n  <c>\n   <d>\n   </d>\n  </c>\n </b>\n</a>", StringComparison.OrdinalIgnoreCase));
        }

        [TestMethod]
        public void ParseAndFormatSelfClosingElements()
        {
            HtmlFormatter p = new HtmlFormatter(" ", true);
            string html = "<a><b /><c><d><b /></d></c></a>";
            Assert.IsTrue(p.Parse(html.ToCharArray()).Equals("\n<a>\n <b />\n <c>\n  <d>\n   <b />\n  </d>\n </c>\n</a>", StringComparison.OrdinalIgnoreCase));
        }

        [TestMethod]
        public void ParseAndFormatTableStructure()
        {
            HtmlFormatter p = new HtmlFormatter(" ", true);
            string html = "<table border=\"1\"\r\nsummary=\"this table summarizes travel expenses\r\nincurred during august trips to\r\nsan jose and seattle\">\r\n<caption>\r\ntravel expense report\r\n</caption>\r\n<tr>\r\n<th></th>\r\n<th id=\"a2\" axis=\"expenses\">meals</th>\r\n<th id=\"a3\" axis=\"expenses\">hotels</th>\r\n<th id=\"a4\" axis=\"expenses\">transport</th>\r\n<td>subtotals</td>\r\n</tr>\r\n<tr>\r\n<th id=\"a6\" axis=\"location\">san jose</th>\r\n<th></th>\r\n<th></th>\r\n<th></th>\r\n<td></td>\r\n</tr>\r\n<tr>\r\n<td id=\"a7\" axis=\"date\">25-aug-97</td>\r\n<td headers=\"a6 a7 a2\">37.74</td>\r\n<td headers=\"a6 a7 a3\">112.00</td>\r\n<td headers=\"a6 a7 a4\">45.00</td>\r\n<td></td>\r\n</tr>\r\n<tr>\r\n<td id=\"a8\" axis=\"date\">26-aug-97</td>\r\n<td headers=\"a6 a8 a2\">27.28</td>\r\n<td headers=\"a6 a8 a3\">112.00</td>\r\n<td headers=\"a6 a8 a4\">45.00</td>\r\n<td></td>\r\n</tr>\r\n<tr>\r\n<td>subtotals</td>\r\n<td>65.02</td>\r\n<td>224.00</td>\r\n<td>90.00</td>\r\n<td>379.02</td>\r\n</tr>\r\n<tr>\r\n<th id=\"a10\" axis=\"location\">seattle</th>\r\n<th></th>\r\n<th></th>\r\n<th></th>\r\n<td></td>\r\n</tr>\r\n<tr>\r\n<td id=\"a11\" axis=\"date\">27-aug-97</td>\r\n<td headers=\"a10 a11 a2\">96.25</td>\r\n<td headers=\"a10 a11 a3\">109.00</td>\r\n<td headers=\"a10 a11 a4\">36.00</td>\r\n<td></td>\r\n</tr>\r\n<tr>\r\n<td id=\"a12\" axis=\"date\">28-aug-97</td>\r\n<td headers=\"a10 a12 a2\">35.00</td>\r\n<td headers=\"a10 a12 a3\">109.00</td>\r\n<td headers=\"a10 a12 a4\">36.00</td>\r\n<td></td>\r\n</tr>\r\n<tr>\r\n<td>subtotals</td>\r\n<td>131.25</td>\r\n<td>218.00</td>\r\n<td>72.00</td>\r\n<td>421.25</td>\r\n</tr>\r\n<tr>\r\n<th>totals</th>\r\n<td>196.27</td>\r\n<td>442.00</td>\r\n<td>162.00</td>\r\n<td>800.27</td>\r\n</tr>\r\n</table>\r\n";
            Assert.IsTrue(p.Parse(html.ToCharArray()).Equals("\n<table border=\"1\"  summary=\"this table summarizes travel expenses  incurred during august trips to  san jose and seattle\">\n <caption>travel expense report\n </caption>\n <tr>\n  <th>\n  </th>\n  <th id=\"a2\" axis=\"expenses\">meals\n  </th>\n  <th id=\"a3\" axis=\"expenses\">hotels\n  </th>\n  <th id=\"a4\" axis=\"expenses\">transport\n  </th>\n  <td>subtotals\n  </td>\n </tr>\n <tr>\n  <th id=\"a6\" axis=\"location\">san jose\n  </th>\n  <th>\n  </th>\n  <th>\n  </th>\n  <th>\n  </th>\n  <td>\n  </td>\n </tr>\n <tr>\n  <td id=\"a7\" axis=\"date\">25-aug-97\n  </td>\n  <td headers=\"a6 a7 a2\">37.74\n  </td>\n  <td headers=\"a6 a7 a3\">112.00\n  </td>\n  <td headers=\"a6 a7 a4\">45.00\n  </td>\n  <td>\n  </td>\n </tr>\n <tr>\n  <td id=\"a8\" axis=\"date\">26-aug-97\n  </td>\n  <td headers=\"a6 a8 a2\">27.28\n  </td>\n  <td headers=\"a6 a8 a3\">112.00\n  </td>\n  <td headers=\"a6 a8 a4\">45.00\n  </td>\n  <td>\n  </td>\n </tr>\n <tr>\n  <td>subtotals\n  </td>\n  <td>65.02\n  </td>\n  <td>224.00\n  </td>\n  <td>90.00\n  </td>\n  <td>379.02\n  </td>\n </tr>\n <tr>\n  <th id=\"a10\" axis=\"location\">seattle\n  </th>\n  <th>\n  </th>\n  <th>\n  </th>\n  <th>\n  </th>\n  <td>\n  </td>\n </tr>\n <tr>\n  <td id=\"a11\" axis=\"date\">27-aug-97\n  </td>\n  <td headers=\"a10 a11 a2\">96.25\n  </td>\n  <td headers=\"a10 a11 a3\">109.00\n  </td>\n  <td headers=\"a10 a11 a4\">36.00\n  </td>\n  <td>\n  </td>\n </tr>\n <tr>\n  <td id=\"a12\" axis=\"date\">28-aug-97\n  </td>\n  <td headers=\"a10 a12 a2\">35.00\n  </td>\n  <td headers=\"a10 a12 a3\">109.00\n  </td>\n  <td headers=\"a10 a12 a4\">36.00\n  </td>\n  <td>\n  </td>\n </tr>\n <tr>\n  <td>subtotals\n  </td>\n  <td>131.25\n  </td>\n  <td>218.00\n  </td>\n  <td>72.00\n  </td>\n  <td>421.25\n  </td>\n </tr>\n <tr>\n  <th>totals\n  </th>\n  <td>196.27\n  </td>\n  <td>442.00\n  </td>\n  <td>162.00\n  </td>\n  <td>800.27\n  </td>\n </tr>\n</table>", StringComparison.OrdinalIgnoreCase));
        }

        [TestMethod]
        public void ParseAndFormatTolerateCDataBlock()
        {
            HtmlFormatter p = new HtmlFormatter(" ", true);
            string html = "<html>\r\n<head>\r\n<title>This is an HTML document</title>\r\n<script type=\"text/javascript\">\r\n//<![CDATA[\r\nvar a=\"abc\";\r\nvar b=\"def\";\r\nvar d=false;\r\nvar f=\"ho ho ho\";\r\n//]]>\r\n</script>\r\n</head>\r\n  <body>\r\n    <ol class=\"alpha\">\r\n      <li>level 1\r\n      <ul>\r\n         <li>level 2</li>\r\n      </ul>\r\n    </li>\r\n    </ol>\r\n  </body>\r\n</html>";
            Assert.IsTrue(p.Parse(html.ToCharArray()).Equals("\n<html>\n <head>\n  <title>This is an HTML document\n  </title>\n </head>  \n <body>    \n  <ol class=\"alpha\">      \n   <li>level 1      \n    <ul>         \n     <li>level 2\n     </li>      \n    </ul>    \n   </li>    \n  </ol>  \n <script type=\"text/javascript\">\r\n//<![CDATA[\r\nvar a=\"abc\";\r\nvar b=\"def\";\r\nvar d=false;\r\nvar f=\"ho ho ho\";\r\n//]]>\r\n </script>\n </body>\n</html>", StringComparison.OrdinalIgnoreCase));
        }

        [TestMethod]
        public void ParseAndFormatTolerateUnclosedElements()
        {
            HtmlFormatter p = new HtmlFormatter(" ", true);
            string html = "<html>\r\n<head>\r\n<title>This is an HTML document</title>\r\n</head>\r\n  <body>\r\n    <ol class=\"alpha\">\r\n      <li>level 1\r\n      <ul>\r\n         <li>level 2\r\n      </ul>\r\n    </ol>\r\n  </body>\r\n</html>";
            Assert.IsTrue(p.Parse(html.ToCharArray()).Equals("\n<html>\n <head>\n  <title>This is an HTML document\n  </title>\n </head>  \n <body>    \n  <ol class=\"alpha\">      \n   <li>level 1      \n    <ul>         \n     <li>level 2      \n    </ul>\n   </ol>\n  </body>\n </html>", StringComparison.OrdinalIgnoreCase));
        }

        [TestMethod]
        public void ParseAndRemoveFormatting()
        {
            HtmlFormatter p = new HtmlFormatter(" ", true);
            p.RemoveFormattingAndSpaces = true;
            string html = "<html>\r\n<head>\r\n<title>This is an HTML document</title>\r\n</head>\r\n  <body>\r\n    <ol class=\"alpha\">\r\n      <li>level 1</li>\r\n      <ul>\r\n         <li>level 2</li>\r\n      </ul>\r\n    </ol>\r\n  </body>\r\n</html>";
            Assert.IsTrue(p.Parse(html.ToCharArray()).Equals("<html><head><title>This is an HTML document</title></head>  <body>    <ol class=\"alpha\">      <li>level 1</li>      <ul>         <li>level 2</li>      </ul>    </ol>  </body></html>", StringComparison.OrdinalIgnoreCase));
        }

        [TestMethod]
        public void ParseAndRemoveFormattingIgnorePreBlock()
        {
            HtmlFormatter p = new HtmlFormatter(" ", true);
            p.RemoveFormattingAndSpaces = true;
            string html = "<table style=\"width: 100%;\">\r\n        <tbody>\r\n          <tr>\r\n            <td colspan=\"2\" style=\"font-weight: bold;\">C#</td>\r\n          </tr>\r\n          <tr>\r\n            <td style=\"text-align: right; vertical-align: top; width: 1%;\">\r\n              <br />\r\n            </td>\r\n            <td style=\"vertical-align: top; width: 99%;\">\r\n              <pre><span style=\"color: rgb(0, 0, 255);\">string</span> ParseAttributeName(<span style=\"color: rgb(0, 0, 255);\">string</span> <span style=\"color: rgb(0, 0, 255);\">value</span>)<br />        {<br />            <span style=\"color: rgb(0, 0, 255);\">if</span> (<span style=\"color: rgb(0, 0, 255);\">string</span>.IsNullOrEmpty(<span style=\"color: rgb(0, 0, 255);\">value</span>)) <span style=\"color: rgb(0, 0, 255);\">return</span> <span style=\"color: rgb(0, 0, 255);\">string</span>.Empty;<br />            <span style=\"color: rgb(0, 0, 255);\">string</span>[] pairs = <span style=\"color: rgb(0, 0, 255);\">value</span>.Split('=');<br />            <span style=\"color: rgb(0, 0, 255);\">return</span> (pairs[0] ?? <span style=\"color: rgb(0, 0, 255);\">string</span>.Empty).Trim();<br />        }<br /></pre>\r\n            </td>\r\n          </tr>\r\n        </tbody>\r\n      </table>";
            Assert.IsTrue(p.Parse(html.ToCharArray()).Equals("<table style=\"width: 100%;\">        <tbody>          <tr>            <td colspan=\"2\" style=\"font-weight: bold;\">C#</td>          </tr>          <tr>            <td style=\"text-align: right; vertical-align: top; width: 1%;\">              <br />            </td>            <td style=\"vertical-align: top; width: 99%;\">              <pre><span style=\"color: rgb(0, 0, 255);\">string</span> ParseAttributeName(<span style=\"color: rgb(0, 0, 255);\">string</span> <span style=\"color: rgb(0, 0, 255);\">value</span>)<br />        {<br />            <span style=\"color: rgb(0, 0, 255);\">if</span> (<span style=\"color: rgb(0, 0, 255);\">string</span>.IsNullOrEmpty(<span style=\"color: rgb(0, 0, 255);\">value</span>)) <span style=\"color: rgb(0, 0, 255);\">return</span> <span style=\"color: rgb(0, 0, 255);\">string</span>.Empty;<br />            <span style=\"color: rgb(0, 0, 255);\">string</span>[] pairs = <span style=\"color: rgb(0, 0, 255);\">value</span>.Split('=');<br />            <span style=\"color: rgb(0, 0, 255);\">return</span> (pairs[0] ?? <span style=\"color: rgb(0, 0, 255);\">string</span>.Empty).Trim();<br />        }<br /></pre></td></tr></tbody></table>", StringComparison.OrdinalIgnoreCase));
        }

        [TestMethod]
        public void ParseAndRemoveFormattingIgnoreScriptBlock()
        {
            HtmlFormatter p = new HtmlFormatter(" ", true);
            p.RemoveFormattingAndSpaces = true;
            string html = "<html>\r\n<head>\r\n<title>This is an HTML document</title>\r\n<script type=\"text/javascript\">\r\n//<![CDATA[\r\n    var a=\"abc\";\r\n    var b=\"def\";\r\n    var d=false;\r\n    var f=\"ho ho ho\";\r\n//]]>\r\n</script>\r\n</head>\r\n  <body>\r\n    <ol class=\"alpha\">\r\n      <li>level 1</li>\r\n      <ul>\r\n         <li>level 2</li>\r\n      </ul>\r\n    </ol>\r\n  </body>\r\n</html>";
            Assert.IsTrue(p.Parse(html.ToCharArray()).Equals("<html><head><title>This is an HTML document</title></head>  <body>    <ol class=\"alpha\">      <li>level 1</li>      <ul>         <li>level 2</li>      </ul>    </ol>  <script type=\"text/javascript\">\r\n//<![CDATA[\r\n    var a=\"abc\";\r\n    var b=\"def\";\r\n    var d=false;\r\n    var f=\"ho ho ho\";\r\n//]]>\r\n </script></body></html>", StringComparison.OrdinalIgnoreCase));
        }

        [TestMethod]
        public void ParseAndRemoveFormattingIgnoreStyleBlock()
        {
            HtmlFormatter p = new HtmlFormatter(" ", true);
            p.RemoveFormattingAndSpaces = true;
            string html = "<html>\r\n<head>\r\n<title>This is an HTML document</title>\r\n<style type=\"text/css\">\r\n    ol.alpha li  { list-style: lower-alpha }\r\n    ul li        { list-style: disc }\r\n  </style>\r\n</head>\r\n  <body>\r\n    <ol class=\"alpha\">\r\n      <li>level 1</li>\r\n      <ul>\r\n         <li>level 2</li>\r\n      </ul>\r\n    </ol>\r\n  </body>\r\n</html>";
            Assert.IsTrue(p.Parse(html.ToCharArray()).Equals("<html><head><title>This is an HTML document</title><style type=\"text/css\">\r\n    ol.alpha li  { list-style: lower-alpha }\r\n    ul li        { list-style: disc }\r\n  </style></head>  <body>    <ol class=\"alpha\">      <li>level 1</li>      <ul>         <li>level 2</li>      </ul>    </ol>  </body></html>", StringComparison.OrdinalIgnoreCase));
        }

        [TestMethod]
        public void ParseDoNotTouchContentNodes()
        {
            List<string> scriptIdIgnoreList = new List<string>();
            scriptIdIgnoreList.Add("someid");
            HtmlFormatter p = new HtmlFormatter(null, null, true, scriptIdIgnoreList);
            string html = "<div>\r\n                     <a href=\"http://www.letsgosomewhere.com\">codeplex</a> k z</div>";
            string result = p.Parse(html.ToCharArray());
            Assert.IsTrue(result.Equals("\n<div>                     \n\t<a href=\"http://www.letsgosomewhere.com\">codeplex\n\t</a> k z\n</div>", StringComparison.OrdinalIgnoreCase));
        }

        [TestMethod]
        public void ParseFormatAllElementsNotInList()
        {
            List<string> noFormattingList = new List<string>();
            noFormattingList.Add("<td>");
            HtmlFormatter p = new HtmlFormatter(" ", null, true, null, noFormattingList);
            string html = "<table><tr><td><a href=\"#\">do not include formatting around this anchor</a></td></tr></table>";
            Assert.IsTrue(p.Parse(html.ToCharArray()).Equals("\n<table>\n <tr>\n  <td><a href=\"#\">do not include formatting around this anchor</a>\n  </td>\n </tr>\n</table>", StringComparison.OrdinalIgnoreCase));
        }

        [TestMethod]
        public void ParseFormatAndTolerateBrokenElementWithoutClosingTag()
        {
            HtmlFormatter p = new HtmlFormatter(" ", true);
            string html = "<ul><li><div class=\"o\" </li><li></li></ul>";
            Assert.IsTrue(p.Parse(html.ToCharArray()).Equals("\n<ul>\n <li><div class=\"o\" \n </li>\n <li>\n </li>\n</ul>", StringComparison.OrdinalIgnoreCase));
        }

        [TestMethod]
        public void ParseFormatDoNotMoveInlineScriptBlockWithSpecificId()
        {
            List<string> scriptIdIgnoreList = new List<string>();
            scriptIdIgnoreList.Add("someid");
            HtmlFormatter p = new HtmlFormatter(null, null, true, scriptIdIgnoreList);
            string html = "<html>\r\n<head>\r\n<title>This is an HTML document</title>\r\n<script id=\"someid\" src=\"/somewhere/here/there.js\" type=\"text/javascript\"></script>\r\n</head>\r\n  <body>\r\n    <ol class=\"alpha\">\r\n      <li>level 1\r\n      <ul>\r\n         <li>level 2</li>\r\n      </ul>\r\n     </li>\r\n    </ol>\r\n  </body>\r\n</html>";
            string result = p.Parse(html.ToCharArray());
            Assert.IsTrue(result.Equals("\n<html>\n\t<head>\n\t\t<title>This is an HTML document\n\t\t</title>\n\t\t<script id=\"someid\" src=\"/somewhere/here/there.js\" type=\"text/javascript\"></script>\n\t</head>  \n\t<body>    \n\t\t<ol class=\"alpha\">      \n\t\t\t<li>level 1      \n\t\t\t\t<ul>         \n\t\t\t\t\t<li>level 2\n\t\t\t\t\t</li>      \n\t\t\t\t</ul>     \n\t\t\t</li>    \n\t\t</ol>  \n\t</body>\n</html>", StringComparison.OrdinalIgnoreCase));
        }

        [TestMethod]
        public void ParseFormatDoNotMoveScriptBlockWithSpecificId()
        {
            List<string> scriptIdIgnoreList = new List<string>();
            scriptIdIgnoreList.Add("someid");
            HtmlFormatter p = new HtmlFormatter(null, null, true, scriptIdIgnoreList);
            string html = "<html>\r\n<head>\r\n<title>This is an HTML document</title>\r\n<script id=\"someid\" type=\"text/javascript\">\r\n//<![CDATA[\r\n    var a=1;\r\n    var b=3;\r\n//]]>\r\n</script>\r\n</head>\r\n  <body>\r\n    <ol class=\"alpha\">\r\n      <li>level 1\r\n      <ul>\r\n         <li>level 2</li>\r\n      </ul>\r\n     </li>\r\n    </ol>\r\n  </body>\r\n</html>";
            string result = p.Parse(html.ToCharArray());
            Assert.IsTrue(result.Equals("\n<html>\n\t<head>\n\t\t<title>This is an HTML document\n\t\t</title>\n\t\t<script id=\"someid\" type=\"text/javascript\">\r\n//<![CDATA[\r\n    var a=1;\r\n    var b=3;\r\n//]]>\r\n</script>\n\t</head>  \n\t<body>    \n\t\t<ol class=\"alpha\">      \n\t\t\t<li>level 1      \n\t\t\t\t<ul>         \n\t\t\t\t\t<li>level 2\n\t\t\t\t\t</li>      \n\t\t\t\t</ul>     \n\t\t\t</li>    \n\t\t</ol>  \n\t</body>\n</html>", StringComparison.OrdinalIgnoreCase));
        }

        [TestMethod]
        public void ParseFormatIgnoreStyleBlockWithAngles()
        {
            HtmlFormatter p = new HtmlFormatter(" ", true);
            string html = "<html>\r\n<head>\r\n<title>This is an HTML document</title>\r\n<style type=\"text/css\">\r\n\thtml>body #wrapper {\r\n  \t\twidth: 750px; /* ..or this reinforcement of the standards width. */\r\n\t}\r\n    html<body{background:yellow;} \r\n</style>\r\n</head>\r\n  <body>\r\n    <ol class=\"alpha\">\r\n      <li>level 1\r\n      <ul>\r\n         <li>level 2</li>\r\n      </ul>\r\n     </li>\r\n    </ol>\r\n  </body>\r\n</html>";
            Assert.IsTrue(p.Parse(html.ToCharArray()).Equals("\n<html>\n <head>\n  <title>This is an HTML document\n  </title>\n  <style type=\"text/css\">\r\n\thtml>body #wrapper {\r\n  \t\twidth: 750px; /* ..or this reinforcement of the standards width. */\r\n\t}\r\n    html<body{background:yellow;} \r\n</style>\n </head>  \n <body>    \n  <ol class=\"alpha\">      \n   <li>level 1      \n    <ul>         \n     <li>level 2\n     </li>      \n    </ul>     \n   </li>    \n  </ol>  \n </body>\n</html>", StringComparison.OrdinalIgnoreCase));
        }

        [TestMethod]
        public void ParseFormatMultipleScriptBlocks()
        {
            HtmlFormatter p = new HtmlFormatter(" ", true);
            string html = "<html>\r\n<head>\r\n<title>This is an HTML document</title>\r\n<script type=\"text/javascript\">\r\n//<![CDATA[\r\n    var a=1;\r\n    var b=3;\r\n    if(a<b)//note usage of angle\r\n\talert('a is less than b');\r\n    else if (a>b)//note usage of angle\r\n\talert(a' is more than b');\r\n//]]>\r\n</script>\r\n</head>\r\n  <body>\r\n<script type=\"text/javascript\">\r\n//<![CDATA[\r\n    \tvar todo=\"yes ok, what\";\r\n\talert(todo);\r\n//]]>\r\n</script>\r\n    <ol class=\"alpha\">\r\n      <li>level 1\r\n      <ul>\r\n         <li>level 2</li>\r\n      </ul>\r\n     </li>\r\n    </ol>\r\n  </body>\r\n</html>";
            Assert.IsTrue(p.Parse(html.ToCharArray()).Equals("\n<html>\n <head>\n  <title>This is an HTML document\n  </title>\n </head>  \n <body>    \n  <ol class=\"alpha\">      \n   <li>level 1      \n    <ul>         \n     <li>level 2\n     </li>      \n    </ul>     \n   </li>    \n  </ol>  \n <script type=\"text/javascript\">\r\n//<![CDATA[\r\n    var a=1;\r\n    var b=3;\r\n    if(a<b)//note usage of angle\r\n\talert('a is less than b');\r\n    else if (a>b)//note usage of angle\r\n\talert(a' is more than b');\r\n//]]>\r\n\r\n//<![CDATA[\r\n    \tvar todo=\"yes ok, what\";\r\n\talert(todo);\r\n//]]>\r\n </script>\n </body>\n</html>", StringComparison.OrdinalIgnoreCase));
        }

        [TestMethod]
        public void ParseFormatScriptBlockWithAngleBrackets()
        {
            HtmlFormatter p = new HtmlFormatter(" ", true);
            string html = "<html>\r\n<head>\r\n<title>This is an HTML document</title>\r\n<script type=\"text/javascript\">\r\n//<![CDATA[\r\n    var a=1;\r\n    var b=3;\r\n    if(a<b)//note usage of angle\r\n\talert('a is less than b');\r\n    else if (a>b)//note usage of angle\r\n\talert(a' is more than b');\r\n//]]>\r\n</script>\r\n</head>\r\n  <body>\r\n    <ol class=\"alpha\">\r\n      <li>level 1\r\n      <ul>\r\n         <li>level 2</li>\r\n      </ul>\r\n     </li>\r\n    </ol>\r\n  </body>\r\n</html>";
            Assert.IsTrue(p.Parse(html.ToCharArray()).Equals("\n<html>\n <head>\n  <title>This is an HTML document\n  </title>\n </head>  \n <body>    \n  <ol class=\"alpha\">      \n   <li>level 1      \n    <ul>         \n     <li>level 2\n     </li>      \n    </ul>     \n   </li>    \n  </ol>  \n <script type=\"text/javascript\">\r\n//<![CDATA[\r\n    var a=1;\r\n    var b=3;\r\n    if(a<b)//note usage of angle\r\n\talert('a is less than b');\r\n    else if (a>b)//note usage of angle\r\n\talert(a' is more than b');\r\n//]]>\r\n </script>\n </body>\n</html>", StringComparison.OrdinalIgnoreCase));
        }

        [TestMethod]
        public void ParseFormatTolerateCommentBlocks()
        {
            HtmlFormatter p = new HtmlFormatter(" ", true);
            string html = "<html>\r\n<head>\r\n<title>This is an HTML document</title>\r\n</head>\r\n  <body>\r\n\t<!-- Now lets have a comment here -->\r\n    <ol class=\"alpha\">\r\n      <li>level 1\r\n      <ul>\r\n         <li>level 2</li>\r\n      </ul>\r\n     </li>\r\n    </ol>\r\n  </body>\r\n</html>";
            Assert.IsTrue(p.Parse(html.ToCharArray()).Equals("\n<html>\n <head>\n  <title>This is an HTML document\n  </title>\n </head>  \n <body><!-- Now lets have a comment here -->    \n  <ol class=\"alpha\">      \n   <li>level 1      \n    <ul>         \n     <li>level 2\n     </li>      \n    </ul>     \n   </li>    \n  </ol>  \n </body>\n</html>", StringComparison.OrdinalIgnoreCase));
        }

        [TestMethod]
        public void ParseFormatTolerateDocDeclaration()
        {
            HtmlFormatter p = new HtmlFormatter(" ", true);
            string html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
            Assert.IsTrue(p.Parse(html.ToCharArray()).Equals("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">", StringComparison.OrdinalIgnoreCase));
        }

        [TestMethod]
        public void ParseFormatTolerateHtmlInScriptBlocks()
        {
            HtmlFormatter p = new HtmlFormatter(" ", true);
            string html = "<body><script type=\"text/javascript\">\r\n    var k=\"<div>html</div>\";\r\n</script></body>";
            Assert.IsTrue(p.Parse(html.ToCharArray()).Equals("\n<body>\n<script type=\"text/javascript\">\r\n    var k=\"<div>html</div>\";\r\n</script>\n</body>", StringComparison.OrdinalIgnoreCase));
        }

        #endregion Methods
    }
}